function jsonp ({url, params, cb}) {
    return new Promise((resolve, reject) => {
        window[cb] = function (data) {
            resolve(data)
            document.body.removeChild(script)
        }
        params = {...params, cb}
        let arrs = []
        for(let key in params) {
            arrs.push(`${key}=${params[key]}`)
        }
        let script = document.createElement('script')
        script = `${url}?${arrs.join('&')}`
        document.body.appendChild(script)
    })
}

jsonp({
    url: 'https://sp0.baidu.com/5a1Fazu8AA54nxGKo9WTAnF6hhy/su',
    params: { wd: 'b'},
    cb: 'show'
}).then(data => {
    console.log(data)
})

// 缺点 只能发送 get 请求， 不支持 post put delete 
// 不安全 xss攻击 